{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对话情绪识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from aip import AipNlp\n",
    "\n",
    "\"\"\" 你的 APPID AK SK \"\"\"\n",
    "APP_ID = '21448228'\n",
    "API_KEY = 'Bh1gj6L4sEfzKMgbRxzFdQMu'\n",
    "SECRET_KEY = 'TTYwGSdlCFP3G6UpLXqZk3csZBxEH4mx'\n",
    "\n",
    "client = AipNlp(APP_ID, API_KEY, SECRET_KEY)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 5134392642393713042,\n",
       " 'text': '本来今天高高兴兴',\n",
       " 'items': [{'subitems': [{'prob': 0.501008, 'label': 'happy'}],\n",
       "   'replies': ['笑一笑十年少'],\n",
       "   'prob': 0.501008,\n",
       "   'label': 'optimistic'},\n",
       "  {'subitems': [], 'replies': [], 'prob': 0.49872, 'label': 'neutral'},\n",
       "  {'subitems': [],\n",
       "   'replies': [],\n",
       "   'prob': 0.000272128,\n",
       "   'label': 'pessimistic'}]}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"本来今天高高兴兴\"\n",
    "\n",
    "\"\"\" 调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"scene\"] = \"talk\"\n",
    "\n",
    "\"\"\" 带参数调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 8470527638397708498,\n",
       " 'text': '你好烦',\n",
       " 'items': [{'subitems': [{'prob': 0.995309, 'label': 'disgusting'}],\n",
       "   'replies': ['我以后会注意的'],\n",
       "   'prob': 0.995309,\n",
       "   'label': 'pessimistic'},\n",
       "  {'subitems': [], 'replies': [], 'prob': 0.00469074, 'label': 'neutral'},\n",
       "  {'subitems': [], 'replies': [], 'prob': 0, 'label': 'optimistic'}]}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"你好烦\"\n",
    "\n",
    "\"\"\" 调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"scene\"] = \"talk\"\n",
    "\n",
    "\"\"\" 带参数调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'log_id': 5985446709798343794,\n",
       " 'text': '你是猪吗',\n",
       " 'items': [{'subitems': [{'prob': 0.835511, 'label': 'disgusting'}],\n",
       "   'replies': ['我再学习学习'],\n",
       "   'prob': 0.835511,\n",
       "   'label': 'pessimistic'},\n",
       "  {'subitems': [], 'replies': [], 'prob': 0.163847, 'label': 'neutral'},\n",
       "  {'subitems': [], 'replies': [], 'prob': 0.000642187, 'label': 'optimistic'}]}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"你是猪吗\"\n",
    "\n",
    "\"\"\" 调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text);\n",
    "\n",
    "\"\"\" 如果有可选参数 \"\"\"\n",
    "options = {}\n",
    "options[\"scene\"] = \"talk\"\n",
    "\n",
    "\"\"\" 带参数调用对话情绪识别接口 \"\"\"\n",
    "client.emotion(text, options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
